<template>
  <div id="app">
    <el-container class="menu">
      <el-header class="header">
        <i class="el-icon-s-grid menumedia" @click="changeMenu"></i>13
      </el-header>
      <el-container>
        <el-aside>
          <el-row class="tac">
            <!--强行加入动画过度隐藏效果-->
            <transition name="el-fade-in">
              <el-menu :default-active="$route.path" class="el-menu-vertical-demo" unique-opened router @open="handleOpen" v-if="!isCollapse"
                       @close="handleClose" :collapse="isCollapse"  :class="{'isCollapseFalseStyle':isCollapse!=true}">
                <template v-for="(item,index) in $router.options.routes" v-if="!item.hidden">
                  <el-submenu :index="index+''" v-if="!item.leaf">
                    <template slot="title">
                      <i :class="item.iconCls"></i>
                      <span slot="title">{{item.name}}</span>
                    </template>
                    <el-menu-item v-for="child in item.children" :index="child.path" :key="child.path"
                                  v-if="!child.hidden">{{child.name}}</el-menu-item>
                  </el-submenu>
                  <el-menu-item v-if="item.leaf&&item.children.length==1" :index="item.children[0].path">
                    <i :class="item.iconCls"></i>
                    <span slot="title"> {{item.children[0].name}}</span>
                  </el-menu-item>
                </template>
              </el-menu>
            </transition>
          </el-row>
        </el-aside>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  name: "Home",
  data() {
    return {
      isCollapse: false   //false为出现 true为隐藏
    }
  },
  methods: {
    handleOpen(key, keyPath) {
      // console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      // console.log(key, keyPath);
    },
    changeMenu() {
      if (this.isCollapse) {
        this.isCollapse = false
      } else {
        this.isCollapse = true
      }
    }
  },
  watch:{
    //监听路由变化，自动缩减左边菜单栏目
    $route(){
      let width=document.body.clientWidth;
      if(width>=700){
        this.isCollapse = false;
      }else{
        this.isCollapse = true;
      }
    }
  },
  mounted(){

  }
};

</script>

<style scoped>
.menu {
  width: 100%;
  height: 100%;
}

.div-logo {
  width: 100%;
  height: 135px;
}
.div-logo img{
  width: 45%;
}
.header {
  font-size: 25px;
  text-align: left !important;
  background: #409EFF;
  color: #333;
  line-height: 60px;
}

.el-footer {
  background-color: #b3c0d1;
  color: #333;
  text-align: center;
  line-height: 60px;
}

.el-aside {
  background-color: #d3dce6;
  color: #333;
  text-align: center;
  line-height: 200px;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  text-align: center;
  // line-height: 160px;
}

body>.el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}

.el-submenu {
  text-align: left;
}

.el-menu-item {
  text-align: left;
}

.el-aside {
  width: auto !important;
}

.isCollapseFalseStyle{
  width: 200px !important;
}

</style>
